package com.example.day09_zuoye.adap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.day09_zuoye.R;
import com.example.day09_zuoye.Rec_Bean;

import java.util.ArrayList;

public class Rec_Adapter extends RecyclerView.Adapter<Rec_Adapter.ViewHorder> {
    Context context;
    ArrayList<Rec_Bean.DataBean.DatasBean> list;

    public Rec_Adapter(Context context, ArrayList<Rec_Bean.DataBean.DatasBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHorder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.rec_layout, parent,false);
        return new ViewHorder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHorder holder, int position) {
        Rec_Bean.DataBean.DatasBean bean = list.get(position);
        Glide.with(context).load(bean.getEnvelopePic()).into(holder.rec_img);
        String desc = bean.getDesc();
        holder.rec_text.setText(desc);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHorder extends RecyclerView.ViewHolder {
        ImageView rec_img;
        TextView rec_text;
        public ViewHorder(@NonNull View itemView) {
            super(itemView);
            rec_img = itemView.findViewById(R.id.rec_img);
            rec_text = itemView.findViewById(R.id.rec_text);
        }
    }
}
